package kr.hkit.androidcomplete01.ch12;

import java.util.ArrayList;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewCode extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.listviewtest);
		
		ArrayList<String> arList = new ArrayList<String>();
		arList.add("김유신");
		arList.add("이순신");
		arList.add("강감찬");
		arList.add("을지문덕");
		
		final ArrayAdapter<String>adapter = new ArrayAdapter<String>(this, 
				android.R.layout.simple_list_item_1, arList);
		ListView listView = (ListView) findViewById(R.id.list);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Toast.makeText(getApplicationContext(), adapter.getItem(position), Toast.LENGTH_LONG).show();
			}
		});
	}
}
